//----------------------------------------------------------------------------
//  ,-.
// /_\___ ,   CA Framework
// '  ___\    (C) Riccardo Capra - http://riccar.do
//  //   \\
//----------------------------------------------------------------------------

#include "NjExample01.h"
#include "NjFundamentalTypesTest.h"
#include "NjTestUnit.h"

//----------------------------------------------------------------------------
void NjFundamentalTypesTest::Run()
{
	NJ_COMPILE_ASSERT(sizeof(NjUint8)==1);
	NJ_COMPILE_ASSERT(sizeof(NjUint16)==2);
	NJ_COMPILE_ASSERT(sizeof(NjUint32)==4);
	NJ_COMPILE_ASSERT(sizeof(NjUint64)==8);

	NJ_COMPILE_ASSERT(sizeof(NjInt8)==1);
	NJ_COMPILE_ASSERT(sizeof(NjInt16)==2);
	NJ_COMPILE_ASSERT(sizeof(NjInt32)==4);
	NJ_COMPILE_ASSERT(sizeof(NjInt64)==8);

	NJ_COMPILE_ASSERT(sizeof(NjFloat32)==4);
	NJ_COMPILE_ASSERT(sizeof(NjFloat64)==8);
	NJ_COMPILE_ASSERT(sizeof(NjFloat)==4 || sizeof(NjFloat)==8);

	NJ_COMPILE_ASSERT(sizeof(NjChar8)==1);
	NJ_COMPILE_ASSERT(sizeof(NjChar16)==2);
	NJ_COMPILE_ASSERT(sizeof(NjChar32)==4);
	NJ_COMPILE_ASSERT(sizeof(NjCharA)==1);
	NJ_COMPILE_ASSERT(sizeof(NjCharA)==sizeof('a'));
	NJ_COMPILE_ASSERT(sizeof(NjCharW)==2 || sizeof(NjCharW)==4);
	NJ_COMPILE_ASSERT(sizeof(NjCharW)==sizeof(L'a'));

	NJ_COMPILE_ASSERT(sizeof(NjUint)==sizeof(void *));
	NJ_COMPILE_ASSERT(sizeof(NjInt)==sizeof(void *));
	
	NJ_TEST_UNITS_GROUP("NjFundamentalTypesTest");
		NJ_TEST_UNIT("Endianness")
			union EndianTest
			{
				NjUint8 m_aData[8];
				NjUint16 m_uInt16;
				NjUint32 m_uInt32;
				NjUint64 m_uInt64;
			};
			
			EndianTest kEndianTest;
			kEndianTest.m_aData[0]=1;
			kEndianTest.m_aData[1]=2;
			kEndianTest.m_aData[2]=3;
			kEndianTest.m_aData[3]=4;
			kEndianTest.m_aData[4]=5;
			kEndianTest.m_aData[5]=6;
			kEndianTest.m_aData[6]=7;
			kEndianTest.m_aData[7]=8;
			
#	if NJ_PLATFORM_BIG_ENDIAN
			static const NjUint16 RESULT_16 = 0x0102;
			static const NjUint32 RESULT_32 = 0x01020304UL;
			static const NjUint64 RESULT_64 = 0x0102030405060708ULL;
#	else // NJ_PLATFORM_BIG_ENDIAN
			static const NjUint16 RESULT_16 = 0x0201;
			static const NjUint32 RESULT_32 = 0x04030201UL;
			static const NjUint64 RESULT_64 = 0x0807060504030201ULL;
#	endif // NJ_PLATFORM_BIG_ENDIAN
 
			NJ_TEST(kEndianTest.m_uInt16==RESULT_16);
			NJ_TEST(kEndianTest.m_uInt32==RESULT_32);
			NJ_TEST(kEndianTest.m_uInt64==RESULT_64);

		NJ_TEST_UNIT_END();
	NJ_TEST_UNITS_GROUP_END();
}
//----------------------------------------------------------------------------
